<?php
namespace Admin\Controller;
use Think\Controller;
class InsurancelistController extends PublicController{
	 public function index(){
		 $this->display();
	 }

	 //获取保险种类

	 public function get_insuran_type(){
	 	$limit = I('get.limit');
		 $page = I('get.page');
		 $like=I('get.like');
		 if(!empty($like)){
			$where["name"] = array("like","%".$like."%");
		  }
		 $ret['total']=M('insurance_type')->count();
		 $ret['data'] = M('insurance_type')
		  ->where($where)
		  ->page($page,$limit)
		  ->select(); 
		  $ret['code'] = 200;
		  ret($ret);
	 }

	 //添加提交
	 public function insert(){
	 	$data['name']=I('post.name');
	 	$re=M('insurance_type')->add($data);
	 	if($re){
	 		$ret['isSuccess']=1;
	 		ret($ret);
	 	}else {
	 		$ret['isSuccess']=0;
	 		ret($ret);
	 	}
	 }

	 //编辑提交
	 public function save(){
	 	$data['id']=I('post.id');
	 	$data['name']=I('post.typename');
	 	$re=M('insurance_type')->where(['id'=>$data['id']])->save($data);
	 	if($re){
	 		$ret['isSuccess']=1;
	 		ret($ret);
	 	}else {
	 		$ret['isSuccess']=0;
	 		ret($ret);
	 	}
	 }

	 //删除种类
	 public function del(){
	 	$id=I('post.id');
	 	$re=M('insurance_type')->where(['id'=>$id])->delete();
	 	if($re){
	 		$ret['isSuccess']=1;
	 		ret($ret);
	 	}else {
	 		$ret['isSuccess']=0;
	 		ret($ret);
	 	}
	 }
}
